class ChangeController < ApplicationController
  before_filter :set_cookies_or_url
  after_filter :log_filter,:except => [:index]  
  include ChangeHelper
  def index
    redirect_to params.merge!(:action => 'show')
  end

  def show
    params[:cn] = params[:cn].to_i
    @oper_type = 11
    @img_style = '1'
    if params[:img_style].nil?
      @img_style = '1'
    else
      @img_style = params[:img_style]
    end
    @back_type = nil
    @pp_style = params[:pp_style]
    if @pp_style.nil?
      @pp_style = 1
    end
    @pp_num = params[:pp_num]
    if @pp_num.nil?
      @pp_num = 2
    end

    @is_a = params[:is_a]
    if @is_a.nil?
      @is_a = 0
    end
    host = request.domain
    le = $level_map[host.swapcase]
    res_l = le[:res_level]
    @col_id = 0
    @res = nil
    unless params[:col_id].to_i == 0
      @col_id = params[:col_id].to_i
      res_arry = Resource.find :all,
        :conditions =>  ["status=? and col_id=? and level <= ? ", 1, @col_id, res_l],
        :order => "rand()",
        :limit => "1"
    else
      res_arry = Resource.find :all,
        :conditions =>  ["status=? and level <= ? ", 1, res_l],
        :order => "rand()",
        :limit => "1"
    end
    if res_arry.size > 0
      @res = res_arry[0]
    end
    if @is_a.to_i == 3
      @play_auto = 20
      if params[:play_auto].to_i != 0
        @play_auto = params[:play_auto].to_i
      end
      @auto_go = "<timer value='#{@play_auto.to_i * 10}'/>"
    else
      @auto_go = nil
    end
    @titles = @res.name + " "+request.domain
    respond_to do |format|
      format.wml
    end
  end

end
